package com.zzptc.shop.servlet;

import com.zzptc.shop.dao.UserDao;
import com.zzptc.shop.vo.Users;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

@javax.servlet.annotation.WebServlet(name = "ZhuCeServlet")
public class ZhuCeServlet extends javax.servlet.http.HttpServlet {
    protected void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, IOException {
        PrintWriter pw = response.getWriter();
        //pw.print("how are you");
        //接受用户请求
        String username = request.getParameter("userName");
        String password = request.getParameter("passWord");
        pw.print(username + "~~~~~~~" + "hello!");

        //调用组件新增数据
        UserDao userDao = new UserDao();
        Users user = new Users();
        user.setEu_user_id("003");
        user.setEu_user_name(username);
        user.setEu_password(password);
        boolean b = false;
        try {
            userDao.insert(user);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        if (b) {
            System.out.println("succ");
        } else {
            System.out.println("error");
        }
    }
}
